<template>
  <div>
    <v-card style="width:100%;">
      <v-card-title>
        <h3>{{name}}</h3>
      </v-card-title>
      <v-card-text>
        <v-form ref="searchForm">
          <v-layout row wrap>
          <v-flex xs12 sm4 md2 class="pr-3">
              <data-picker :title="'开始时间'" :ui="'menu'" :date="sdate" @upDate="sDateValue"/>
          </v-flex>
          <v-flex xs12 sm4 md2 class="pr-3">
            <data-picker :title="'结束时间'" :ui="'menu'" :date="edate" @upDate="eDateValue"/>
          </v-flex>
            <v-spacer></v-spacer>
            <v-flex xs12 sm4 md2 class="pr-3">
              <v-btn color="primary" @click.stop="pubReportSearch" small><h4>查询</h4></v-btn>
            </v-flex>
          </v-layout>
        </v-form>

      </v-card-text>
    </v-card>
    <p></p>
      <v-card >
        <v-card-title>
          <v-btn dark color="teal" @click.stop="publishReportDownload" small><v-icon dark>file_download</v-icon></v-btn>
        </v-card-title>
          <v-data-table
            :headers="headers"
            :items="items"
            :pagination.sync="pagination"
            :total-items="totalItems"
            :loading="loading"
            :rows-per-page-items="rowsPerPageItems"
            :no-data-text="etext"
            class="elevation-1">
            <template slot="items" slot-scope="props">
               <td class="reportstyle" v-for="(value) in headers" :key="value.id">{{props.item[value.value]}}</td>
            </template>
            <template slot="no-data">
              <v-alert :value="true" color="error" icon="warning">
                {{etext}}
              </v-alert>
            </template>
          </v-data-table>
      </v-card>
  </div>
</template>

<script>
import { createNamespacedHelpers } from 'vuex'
const { mapActions } = createNamespacedHelpers('publish_report')
export default {
  data: function () {
    return this.$store.state.publish_report
  },
  watch: {
    pagination () {
      this.handlerPublishReport()
    },
    search () {
      this.handlerPublishReport()
    }
  },
  methods: {
    ...mapActions({
      handlerPublishReport: 'handlerPublishReport',
      loadPublishReportFilters: 'loadPublishReportFilters',
      publishReportDownload: 'publishReportDownload',
      loadPublishReportHeaders: 'loadPublishReportHeaders',
      pubReportSearch: 'pubReportSearch'
    }),
    sDateValue (date) {
      this.sdate = date
    },
    eDateValue (date) {
      this.edate = date
    }
  },
  mounted () {
    this.loadPublishReportHeaders()
  },
  components: {
    'data-picker': () => import('../../components/dateTimePicker/dataPicker')
  }
}
</script>
